package com.lhkj.ct.admin.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.lhkj.ct.base.annntation.Log;
import com.lhkj.ct.base.enums.ActionType;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.model.ro.ActionResult;
import com.lhkj.ct.meta.admin.model.entity.TblOperationLog;
import com.lhkj.ct.meta.admin.service.OperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 *     操作日志
 * </p>
 */
@RestController
@RequestMapping("api/system/log/operation")
@ApiSupport(order = 10)
@Api(tags = {"10.操作日志"})
@Validated
//@RequiresRoles(value = {SystemConstants.ADMIN_ROLE_CODE})
public class OperationLogController {


    @Resource
    private OperationLogService operationLogService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "操作日志列表", notes = "分页查询")
    ////@RequiresPermissions("system:operationLog:list")
    @GetMapping("/list")
    public ActionResult<IPage<TblOperationLog>> list(TblOperationLog operationLog, PageQuery pageQuery) {
        return ActionResult.success(operationLogService.selectOperationLogPage(operationLog, pageQuery));
    }

//    @ApiOperationSupport(order = 1)
//    @ApiOperation(value = "操作日志列表", notes = "分页查询")
//    @Log(title = "操作日志", actionType = OperateType.CLEAN)
//    ////@RequiresPermissions("system:operationLog:export")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TblOperationLog operLog) {
////        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
////        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
////        util.exportExcel(response, list, "操作日志");
//    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "删除日志")
    @Log(title = "操作日志", actionType = ActionType.DELETE)
    ////@RequiresPermissions("system:operationLog:delete")
    @DeleteMapping("/delete")
    public ActionResult<Void> remove(@Validated @NotEmpty(message = "日志id不能为空") @RequestBody List<String> operIds) {
        return ActionResult.judge(operationLogService.removeByIds(operIds));
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "清空日志")
    @Log(title = "操作日志", actionType = ActionType.CLEAN)
    ////@RequiresPermissions("system:operationLog:delete")
    @DeleteMapping("/clean")
    public ActionResult<Void> clean() {
        operationLogService.cleanOperationLog();
        return ActionResult.success();
    }
}
